package swu.myt;

import java.io.IOException;
import java.io.Writer;
import java.sql.SQLException;
import java.text.SimpleDateFormat;
import java.util.List;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class UserHomeServlet extends HttpServlet{
	private static final long serialVersionUID = 2860175530630633043L;
 
	public void init() {
		System.out.println("initialized!");
	}

	public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
		this.doPost(request, response);
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
		System.out.println("Servlet Serving");
		String username = request.getParameter("name");//得到数据
		
		
		response.setContentType("text/html");//设置类型
		response.setCharacterEncoding("UTF-8");//设置字符集
		
		try (Writer writer = response.getWriter()) {//写登陆进去后的页面
			StringBuilder sb = new StringBuilder();
			sb.append("<html>");
			sb.append("<head><meta http-equiv='Content-Type' content='text/html; charset=UTF-8'/><title>user home</title></head>");
			sb.append("<body><center>");
			sb.append(String.format("<h2 style='color:#%s'>Hello,%s!</h2><br>", "000000", username));
			sb.append(String.format("<div style='width:700px'>Login Success!Have a good time!^^</div>", username));	
			sb.append(String.format("<br><br><form action=\"./page.html\" method=\"POST\">\r\n"
					+ "	<input type=\"submit\" value=\"upload\" />\r\n"
					+ "	</form>"));	
			sb.append(String.format("<br><br><form action=\"./records.jsp\" method=\"POST\">\r\n"
					+ "	<input type=\"submit\" value=\"records\" />\r\n"
					+ "	</form>"));
			sb.append("</center></body></html>");	
			writer.write(sb.toString());
			writer.flush();
			
			
			
			
			
			
			
			}
		
		}
			
			
	public void destory() {
		System.out.println("Servlet Destoried.");
	}

	
	
	
}
